package sanshui.system.trade.factory.trade.strategy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sanshui.system.trade.config.ClassPathScanner;
import sanshui.system.trade.factory.trade.riskCtr.AbstractRiskStrategy;
import sanshui.system.trade.factory.trade.riskCtr.RiskCtrCode;
import sanshui.system.trade.factory.trade.strategy.impl.DefaultStrategy;
import sanshui.system.trade.factory.trade.strategy.impl.M45Strategy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class StrategyFactory {

    List<AbstractStrategy> strategyList;
    List<AbstractRiskStrategy> riskCtlStrategyList;
    @Autowired
    public StrategyFactory(List<AbstractStrategy> strategyList, List<AbstractRiskStrategy> riskCtlStrategyList){
        this.strategyList = strategyList;
        this.riskCtlStrategyList = riskCtlStrategyList;
    }

    public AbstractStrategy getTradeStrategy(StrategyCode code) {
        for (AbstractStrategy abstractStrategy : strategyList) {
            if (abstractStrategy.getStrategyCode().compareTo(code) == 0){
                return abstractStrategy;
            }
        }
        log.error("没有找到对应的StrategyCode， code:{}", code);
        return null;
    }

    public boolean isHas(StrategyCode strategyCode){
        for (AbstractStrategy abstractStrategy : strategyList) {
            if (abstractStrategy.getStrategyCode().compareTo(strategyCode) == 0){
                return true;
            }
        }
        return false;
    }

    public List<String> getAllStrategyCode(){
        List<String> res = new ArrayList<>();
        for (AbstractStrategy abstractStrategy : strategyList) {
            res.add(abstractStrategy.getStrategyCode().getCode());
        }
        return res;
    }

    public AbstractRiskStrategy getRiskStrategy(RiskCtrCode code) {
        for (AbstractRiskStrategy abstractStrategy : riskCtlStrategyList) {
            if (abstractStrategy.getRiskName().compareTo(code) == 0){
                return abstractStrategy;
            }
        }
        log.error("没有找到对应的RiskCode， code:{}", code);
        return null;
    }

    public boolean isHas(RiskCtrCode strategyCode){
        for (AbstractRiskStrategy abstractStrategy : riskCtlStrategyList) {
            if (abstractStrategy.getRiskName().compareTo(strategyCode) == 0){
                return true;
            }
        }
        return false;
    }

    public List<String> getAllRiskCtrCode(){
        List<String> res = new ArrayList<>();
        for (AbstractRiskStrategy abstractStrategy : riskCtlStrategyList) {
            res.add(abstractStrategy.getRiskName().getCode());
        }
        return res;
    }
}
